package com.flower.controller.admin;

import com.flower.domain.dto.admin.LogDto;
import com.flower.domain.entity.SysLog;
import com.flower.service.LogService;
import com.flower.utils.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理端日志
 */
@RestController
@RequestMapping("/log")
@Slf4j
public class LogController {
    @Autowired
    private LogService logService;

    /**
     * 获取日志列表
     * @param logDto 查询参数
     * @return 日志分页数据
     */
    @GetMapping("/getLogList")
    public AjaxResult getLogList(LogDto logDto) {
        log.info("获取日志列表: pageNumber={}, pageSize={}, name={}, username={}, ip={}", 
                logDto.getPageNumber(), logDto.getPageSize(), logDto.getName(), 
                logDto.getUsername(), logDto.getIp());
        return AjaxResult.success(logService.pageList(logDto));
    }
    
    /**
     * 获取日志详情
     * @param id 日志ID
     * @return 日志详情
     */
    @GetMapping("/detail/{id}")
    public AjaxResult getLogDetail(@PathVariable Long id) {
        log.info("获取日志详情: id={}", id);
        SysLog sysLog = logService.getById(id);
        if (sysLog == null) {
            return AjaxResult.error("日志不存在");
        }
        return AjaxResult.success(sysLog);
    }
}
